package com.pet.shop.controller.pet;

import com.pet.config.SessionConstants;
import com.pet.shop.controller.BaseController;
import com.pet.shop.entity.shop.PetDisinsection;
import com.pet.shop.entity.user.SysUser;
import com.pet.shop.service.IBaseService;
import com.pet.shop.service.pet.IPetDisinsectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@Controller
@RequestMapping("/web/petDisinsection")
public class PetDisinsectionController extends BaseController<PetDisinsection> {

    @Autowired
    private IPetDisinsectionService petDisinsectionService;

    @Override
    public IBaseService<PetDisinsection> getBaseService() {
        return petDisinsectionService;
    }

    @Override
    public Map<String, Object> insertEntity(HttpServletRequest request, PetDisinsection entity) {
        entity.setOptUserId(getSessionUser(request).getId());
        return super.insertEntity(request, entity);
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值，false:不能为空值
    }
}
